import 'package:flutter/material.dart';
import 'package:shining_red_star/widgets/shape.dart';
import '../definitions/color.dart';
import '../model/shape.dart';
import 'focus_manage/focus_widget.dart';

class ShapeIndexCard extends StatefulWidget {
  final ShapeInfo shape;
  final FocusNode focusNode;
  final bool? autofocus;
  final void Function()? onConfirm;

  ShapeIndexCard({
    super.key,
    required this.shape,
    this.autofocus,
    this.onConfirm,
    FocusNode? focusNode,
  }) : focusNode = focusNode ?? FocusNode();

  @override
  State<ShapeIndexCard> createState() => _ShapeIndexCardState();
}

class _ShapeIndexCardState extends State<ShapeIndexCard> {
  @override
  Widget build(BuildContext context) {
    bool showFocusStatus = widget.focusNode.hasFocus;
    return FocusWidget(
        focusNode: widget.focusNode,
        autofocus: widget.autofocus,
        onConfirm: widget.onConfirm,
        onFocusChange: (bool value) {
          setState(() {});
        },
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10),
              border: Border.all(
                  color: showFocusStatus
                      ? SchemeColor.seedColor.value
                      : Colors.white30)),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Shape(
                shapeId: widget.shape.id,
                color: widget.shape.fillColor,
              ),
              Text(
                widget.shape.value,
                style: TextStyle(
                  height: 1,
                  fontSize: 18,
                  fontWeight: showFocusStatus ? FontWeight.bold : null,
                  color: showFocusStatus ? SchemeColor.seedColor.value : null,
                ),
              )
            ],
          ),
        ));
  }
}
